#! /bin/csh -f

# sm_test: SM component test script

#
# DBHOME:  This is the directory where dbcreate, redbase, and dbdestroy are
#
set DBHOME = .

#
# TESTSDIR:  This is the directory where the files of test queries
# are.  
#
set TESTSDIR = .

#
# This is the name of the data base we will be using for the tests.
#
set TESTDB = testdb


#
# This is the name of the output file we will use for the tests.
#
set OUTPUT = /dev/stdout

#
# Run the requested tests
#

#
# if no args given, then run all tests
#

if ( $#argv == 0 ) then
   echo "SM layer test sequence" >! $OUTPUT

   foreach queryfile ( `ls $TESTSDIR/sm_test.*` )
      $DBHOME/dbdestroy $TESTDB || :
      echo running test '#' $queryfile:e '****************' >> $OUTPUT
      $DBHOME/dbcreate  $TESTDB
      $DBHOME/redbase   $TESTDB < $queryfile >>& $OUTPUT
   end

#
# otherwise, run just the specified tests
#

else
   foreach testnum ( $* )
      if ( -r $TESTSDIR/sm_test.$testnum ) then
         $DBHOME/dbdestroy $TESTDB || :
         echo running test '#' $testnum '****************' >> $OUTPUT
         $DBHOME/dbcreate  $TESTDB
         $DBHOME/redbase   $TESTDB < $TESTSDIR/sm_test.$testnum >>& $OUTPUT
      else
         echo I can not find a test number $testnum. >> $OUTPUT
      endif
   end
endif
